import { WebSocketGateway, SubscribeMessage, MessageBody, ConnectedSocket,WsResponse } from '@nestjs/websockets';
import { Logger } from '@nestjs/common';
import * as WebSocket from 'ws';
import { IncomingMessage } from 'http';

@WebSocketGateway(4399, { cors: true, maxHttpBufferSize: '1e8' })
export class WsGateway {

  async handleConnection(client: WebSocket, request: IncomingMessage) {
    console.log(request.url);
    console.log(client._socket.server._connections);
  }

  handleDisconnect(client: WebSocket) {
    console.log(client._socket.server._connections);
  }

  
  @SubscribeMessage('event')
  sendText(@ConnectedSocket() client: WebSocket,@MessageBody() data: any) {
    Logger.log('客户端发送的数据：' + JSON.stringify(data));
    client.send(data)
  }

}
